package com.hkbigdata.springbootdi.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.hkbigdata.springbootdi.bean.OrderStatus;
import com.hkbigdata.springbootdi.mapper.MysqlMapper;
import com.hkbigdata.springbootdi.service.DiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liuanbo
 * @creat 2024-12-04-10:48
 * @see 2194550857@qq.com
 */
@Service
public class DiServiceImpl implements DiService {
    @Autowired
    MysqlMapper mysqlMapper;

    @Override
    public JSONObject queryOrderStatus(String dt) {
        List<OrderStatus> orderStatus = mysqlMapper.getOrderStatus(dt);
        //接受最终返回值
        JSONObject result = new JSONObject();
        JSONObject data = new JSONObject();

        ArrayList<String> categoriesJSON = new ArrayList<>();
        ArrayList<JSONObject> seriesJSON = new ArrayList<>();

        JSONObject orderjosn = new JSONObject();
        JSONObject refundjson = new JSONObject();

        ArrayList<Integer> orderdatajson = new ArrayList<>();
        ArrayList<Integer> refunddatajson = new ArrayList<>();

        //遍历数据并且将其进行添加到list。
        for (OrderStatus status : orderStatus) {
            categoriesJSON.add(status.getTime());
            orderdatajson.add(status.getOrderCount());
            refunddatajson.add(status.getRefundCount());
        }

        orderjosn.put("name", "新增订单数");
        orderjosn.put("data", orderdatajson);
        refundjson.put("name", "退款订单数");
        refundjson.put("data", refunddatajson);


        seriesJSON.add(orderjosn);
        seriesJSON.add(refundjson);

        data.put("categories", categoriesJSON);
        data.put("series", seriesJSON);

        result.put("status", 0);
        result.put("msg", "查询成功");
        result.put("data", data);


        return result;
    }
}
